const getters = {
  sidebar: state => state.app.sidebar,
  size: state => state.app.size,
  device: state => state.app.device,
  visitedViews: state => state.tagsView.visitedViews,
  cachedViews: state => state.tagsView.cachedViews,
  token: state => state.user.token,
  avatar: state => state.user.avatar,
  name: state => state.user.name,
  introduction: state => state.user.introduction,
  roles: state => state.user.roles,
  permission_routes: state => state.permission.routes,
  errorLogs: state => state.errorLog.logs,
  storeList: state => {
    return state.store.storeList?.data || [];
  },
  curStore: state => state.store.curStore,

  storeHouseList: state => {
    const list = { ...state.store.storeHouseList };
    const curStore = state.store.curStore;
    if (curStore && curStore?.id && list?.data) {
      list.data = state.store.storeHouseList.data.filter(d => d.store_id === curStore.id);
    }
    return list;
  },
  storeHouseDict: state => {
    const storeHouseList = { ...state.store.storeHouseList };
    const dict = {};
    if (storeHouseList && storeHouseList?.data) {
      storeHouseList.data.forEach(d => {
        dict[d.id] = d;
      })
    }
    return dict;
  },
  category: state => {
    const category = { ...state.goods.category };
    const curStore = state.store.curStore;
    console.log('getters--category==', category, state.goods.category);

    if (curStore && curStore?.id && category?.data) {
      category.data = state.goods.category.data.filter(d => d.store_id === curStore.id);
    }
    return category;
  },
  dictList: state => {
    const list = { ...state.system.dictList };
    const curStore = state.store.curStore;
    if (curStore && curStore?.id && list?.data) {
      list.data = state.system.dictList.data.filter(d => d.store_id === curStore.id);
    }
    return list;
  },
  goodsCategoryDict: state => {
    const category = state.goods.category?.data || [];
    const categoryDict = {};
    const curStore = state.store.curStore;
    category.forEach(d => {
      if (curStore && curStore?.id) {
        if (curStore.id === d.store_id) {
          categoryDict[d.cat_id] = { ...d };
        }
      }
      else {
        categoryDict[d.cat_id] = { ...d };
      }
    })
    return categoryDict;
  }
}
export default getters
